<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #banner {
      width: 500px;
      height: 400px;
      margin: 20px auto;
      position: relative;
      overflow: hidden;
    }

    #banner .slide_wrap {
      width: 500px;
      height: 400px;
    }

    #banner .slide_wrap>div {
      width: 500px;
      height: 400px;
      display: none;
    }

    #banner .slide_wrap>div:nth-child(1) {
      width: 500px;
      height: 400px;
      display: block;
    }

    #banner .slide_wrap>div img {
      width: 500px;
      height: 400px;
    }

    .banner_nav {
      width: 200px;
      height: 20px;
      /* background: darkblue; */
      position: absolute;
      bottom: 40px;
      left: 50%;
      margin-left: -100px;
      display: flex;
      justify-content: space-around;
      cursor: pointer;
    }

    .banner_nav li {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: red;
      list-style: none;
    }

    .banner_nav .active {
      background: white;
    }

    .banner_ctrl div {
      font-size: 60px;
      font-family: "黑体";
      position: absolute;
      top: 40%;
      color: white;
      background: rgba(0, 0, 0, 0.5);
      cursor: pointer;
    }

    .banner_ctrl .prev {
      left: 30px;
    }

    .banner_ctrl .next {
      right: 30px;
    }
  </style>
</head>

<body>
  <div id="banner">
    <!-- 图片部分 -->
    <div class="slide_wrap">
      <div>
        <img src="./img/1.png" alt="">
      </div>
      <div>
        <img src="./img/2.png" alt="">
      </div>
      <div>
        <img src="./img/3.png" alt="">
      </div>
      <div>
        <img src="./img/4.png" alt="">
      </div>
    </div>
    <!-- 圆点部分 -->
    <ul class="banner_nav">
      <li class="active"></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>
    <!-- 控制器部分 -->
    <div class="banner_ctrl">
      <div class="prev">&lt;</div>
      <div class="next">&gt;</div>
    </div>
  </div>
  <script src="./jquery-3.4.1.min.js"></script>
  <script>
    var num = 0; //公共下标
    var timer = null;
    // 自动轮播
    function move() {
      num++;
      if (num > $(".slide_wrap>div").length - 1) {
        num = 0;
      }
      change()
    }
    timer = setInterval(move, 2000)//俩秒
    // 鼠标移入移出
    $("#banner").mouseenter(function () {
      clearInterval(timer)
    }).mouseleave(function () {
      timer = setInterval(move, 2000)//俩秒
    })
    // 圆点点击
    $(".banner_nav li").click(function () {
      num = $(this).index();
      change()
    })
    // 前点击事件
    $(".prev").click(function () {
      num--
      if (num < 0) {
        num = $(".slide_wrap>div").length - 1
      }
      change()
    })
    // 后点击
    $(".next").click(function () {
      move()
    })
    // 改变方法
    function change() {
      // 小圆点 改变
      $("li").eq(num).addClass("active").siblings().removeClass("active")
      // div 改变
      $(".slide_wrap>div").eq(num).fadeIn(300).siblings().fadeOut(300)
    }


  </script>
</body>

</html>